home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_051 / bison / diffs / bisondiffs next >
Internet Message Format  |  1992-05-06  |  11KB

  1. From noao!seismo!ism780c!dougl Mon Dec 15 23:31:28 1986
  2. Return-Path: <noao!seismo!ism780c!dougl>
  3. Received: by mcdsun.uucp (3.2/SMI-3.2)
  4.     id AA00990; Mon, 15 Dec 86 23:31:22 MST
  5. From: noao!seismo!ism780c!dougl
  6. Received: by noao.ARPA (5.51/SAG.4)
  7.     id AA03654; Mon, 15 Dec 86 21:11:50 MST
  8. Received: from ism780c.UUCP by seismo.CSS.GOV (5.54/1.14) with UUCP 
  9.     id AA04556; Mon, 15 Dec 86 13:18:24 EST
  10. Date: Mon, 15 Dec 86 13:18:24 EST
  11. Message-Id: <8612151818.AA04556@seismo.CSS.GOV>
  12. Sender: noao!seismo!ism780c!dougl
  13. Subject: bison update (NOW it works on the AMIGA)
  14. To: noao!mcdsun!fnf
  15. Status: RO
  16.  
  17. To: seismo!noao!mcdsun!fnf
  18. Fred,
  19.  
  20. Enclosed in the following shar script are the necessary changes to make
  21. bison (fish #4) work correctly on the amiga.  I did not bother making a
  22. floppy etc for this because the changes, once I figured out what was
  23. going on were pretty minimal.  The problem seems to be that bison trys
  24. to unallocate non allocated memory as well as allocated memory.  The
  25. unix malloc checks for this type of case and doesn't do anything.  I
  26. set up allocate/FREE to do a similar thing.  Also the clearing of memory
  27. in the allocate routine seems to be causing problems.  I changed it to
  28. simply call calloc instead.  I added a string.h type file, although it
  29. doesn't need any of the return codes from the string functions, I wanted
  30. to remove that error message.  Finally I changed calc, so that typing a
  31. 'Q' as a command will exit out of the calc program.  (I got tired of
  32. rebooting everytime I tested the calc program).  You should be able
  33. drop these changes over the bison on fish #4, and get a working bison.
  34.  
  35. I thought fixing bison up would be a lot easier than writing my own.
  36. Thanks again for the idea of using the ANSI.C (mod.sources) parser,
  37. I have a copy, that I've updated to current standards, and now with
  38. bison I might be able to make some better progress.
  39.  
  40. I haven't sent these changes onto the GNU people as I currently
  41. don't an address.  If you have an address, could you pass on the changes,
  42. and possibly the address back this way?
  43.  
  44.         Have a Nice christmas,
  45.         Doug Leavitt
  46.  
  47. ------------------- CUT HERE ------------------------------------------
  48. #    This is a shell archive.
  49. #    Remove everything above and including the cut line.
  50. #    Then run the rest of the file through sh.
  51. #----cut here-----cut here-----cut here-----cut here----#
  52. #!/bin/sh
  53. # shar:    Shell Archiver
  54. #    Run the following text with /bin/sh to create:
  55. #    string.h
  56. #    new.h
  57. #    allocate.c
  58. #    calc.y
  59. # This archive created: Sun Dec 14 12:52:21 1986
  60. cat << \SHAR_EOF > string.h
  61. /*
  62.  * string function definition file, used in the amiga port of
  63.  * bison.
  64.  */
  65. /* Definitions for string routines, when the string file doesn't exist
  66.    IE for the amiga port of bison
  67.    copyright (C) 1986  Douglas J Leavitt (this file only)
  68.  
  69.    Permission is granted to anyone to make or distribute verbatim copies of this program
  70.    provided that the copyright notice and this permission notice are preserved;
  71.    and provided that the recipient is not asked to waive or limit his right to
  72.    redistribute copies as permitted by this permission notice;
  73.    and provided that anyone possessing an executable copy
  74.    is granted access to copy the source code, in machine-readable form,
  75.    in some reasonable manner.
  76.  
  77.    Permission is granted to distribute derived works or enhanced versions of
  78.    this program under the above conditions with the additional condition
  79.    that the entire derivative or enhanced work
  80.    must be covered by a permission notice identical to this one.
  81.  
  82.    Anything distributed as part of a package containing portions derived
  83.    from this program, which cannot in current practice perform its function usefully
  84.    in the absense of what was derived directly from this program,
  85.    is to be considered as forming, together with the latter,
  86.    a single work derived from this program,
  87.    which must be entirely covered by a permission notice identical to this one
  88.    in order for distribution of the package to be permitted.
  89.  
  90.  In other words, you are welcome to use, share and improve this program.
  91.  You are forbidden to forbid anyone else to use, share and improve
  92.  what you give them.   Help stamp out software-hoarding!  */
  93.  
  94. extern char    *strcat(), *strncat(), *strcpy(), *strncpy();
  95. extern char    *strchr(), *strrchr();
  96. extern int     strcmp(),  strncmp(), strlen();
  97. SHAR_EOF
  98. cat << \SHAR_EOF > new.h
  99. /* Storage allocation interface for bison,
  100.    copyright (C) 1984 Bob Corbett and Richard Stallman
  101.  
  102.    Permission is granted to anyone to make or distribute verbatim copies of this program
  103.    provided that the copyright notice and this permission notice are preserved;
  104.    and provided that the recipient is not asked to waive or limit his right to
  105.    redistribute copies as permitted by this permission notice;
  106.    and provided that anyone possessing an executable copy
  107.    is granted access to copy the source code, in machine-readable form,
  108.    in some reasonable manner.
  109.  
  110.    Permission is granted to distribute derived works or enhanced versions of
  111.    this program under the above conditions with the additional condition
  112.    that the entire derivative or enhanced work
  113.    must be covered by a permission notice identical to this one.
  114.  
  115.    Anything distributed as part of a package containing portions derived
  116.    from this program, which cannot in current practice perform its function usefully
  117.    in the absense of what was derived directly from this program,
  118.    is to be considered as forming, together with the latter,
  119.    a single work derived from this program,
  120.    which must be entirely covered by a permission notice identical to this one
  121.    in order for distribution of the package to be permitted.
  122.  
  123.  In other words, you are welcome to use, share and improve this program.
  124.  You are forbidden to forbid anyone else to use, share and improve
  125.  what you give them.   Help stamp out software-hoarding!  */
  126.  
  127. #define    NEW(t)        ((t *) allocate((unsigned) sizeof(t)))
  128. #define    NEW2(n, t)    ((t *) allocate((unsigned) ((n) * sizeof(t))))
  129.  
  130. #ifdef    AMIGA
  131. #define FREE(x)        bisonfree(x);
  132. #else
  133. #define    FREE(x)        {if(x) free((char *) (x));}
  134. #endif
  135.  
  136.  
  137. extern    char *allocate();
  138. SHAR_EOF
  139. cat << \SHAR_EOF > allocate.c
  140. /* Allocate and clear storage for bison,
  141.    copyright (C) 1984 Bob Corbett and Richard Stallman
  142.  
  143.    Permission is granted to anyone to make or distribute verbatim copies of this program
  144.    provided that the copyright notice and this permission notice are preserved;
  145.    and provided that the recipient is not asked to waive or limit his right to
  146.    redistribute copies as permitted by this permission notice;
  147.    and provided that anyone possessing an executable copy
  148.    is granted access to copy the source code, in machine-readable form,
  149.    in some reasonable manner.
  150.  
  151.    Permission is granted to distribute derived works or enhanced versions of
  152.    this program under the above conditions with the additional condition
  153.    that the entire derivative or enhanced work
  154.    must be covered by a permission notice identical to this one.
  155.  
  156.    Anything distributed as part of a package containing portions derived
  157.    from this program, which cannot in current practice perform its function usefully
  158.    in the absense of what was derived directly from this program,
  159.    is to be considered as forming, together with the latter,
  160.    a single work derived from this program,
  161.    which must be entirely covered by a permission notice identical to this one
  162.    in order for distribution of the package to be permitted.
  163.  
  164.  In other words, you are welcome to use, share and improve this program.
  165.  You are forbidden to forbid anyone else to use, share and improve
  166.  what you give them.   Help stamp out software-hoarding!  */
  167.  
  168. #include <stdio.h>
  169.  
  170.  
  171. char *
  172. allocate(n)
  173. register unsigned n;
  174. {
  175.   register char *block;
  176.   register char *cp;
  177.   register char *cend;
  178.   register int *ip;
  179.  
  180. #ifdef    AMIGA
  181.   extern char *calloc();
  182. #else
  183.   extern char *malloc();
  184. #endif
  185.  
  186. #ifdef    AMIGA
  187.   block = calloc(n+4,1);
  188. #else
  189.   block = malloc(n);
  190. #endif
  191.   if (block == NULL)
  192.     {
  193.       fprintf(stderr, "storage limit exceeded");
  194.       done(1);
  195.     }
  196.  
  197. #ifdef    AMIGA
  198.   block[0] = 'A';
  199.   block[1] = 'M';
  200.   block[2] = 'E';
  201.   block[3] = 'M';
  202.   return(block+4);
  203. #else
  204.   cp = block;
  205.   cend = block + n;
  206.   while (cp < cend)
  207.     *cp++ = 0;
  208.   if (n < 4)
  209.     {
  210.       while (cp < cend)
  211.     *cp++ = 0;
  212.     }
  213.   else
  214.     {
  215.       while (((unsigned) cp) & 3)
  216.     *cp++ = 0;
  217.  
  218.       ip = (int *) cp;
  219.       while (ip < (int *) cend)
  220.     *ip++ = 0;
  221.  
  222.       cp = (char *) ip;
  223.       while (cp < cend)
  224.     *cp++ = 0;
  225.     }
  226.  
  227.   return (block);
  228. #endif
  229. }
  230.  
  231. #ifdef    AMIGA
  232. bisonfree(loc)
  233. char    *loc;
  234. {
  235.     register unsigned long l1, l2;
  236.     register char *p;
  237.  
  238.     if (loc == (char *)0)
  239.         return;
  240.     l1 = (unsigned long)loc;
  241.     l2 = l1 - 4;
  242.     if (l2 > l1)
  243.         return;        /* check for wrap */
  244.     p = (char *)l2;
  245.     if (p[0] != 'A' || p[1] != 'M' || p[2] != 'E' || p[3] != 'M')
  246.         return;        /* Not allocated memory */
  247.     free(p);        /* Free the real location */
  248. }
  249. #endif
  250. SHAR_EOF
  251. cat << \SHAR_EOF > calc.y
  252. %{
  253. #include <ctype.h>
  254.  
  255. int regs[26];
  256. int base;
  257.  
  258. int val;
  259. int printflag;
  260.  
  261. %}
  262.  
  263. %start stmt
  264.  
  265. %token DIGIT LETTER EXIT
  266.  
  267. %left '|'
  268. %left '&'
  269. %left '+' '-'
  270. %left '*' '/' '%'
  271. %left UMINUS
  272.  
  273. %%
  274.  
  275. stmt    :    expr
  276.             { val = $1; printflag = 1; }
  277.     |     LETTER '=' expr
  278.             { regs[$1] = $3; }
  279.     |    EXIT
  280.             { exit(0); }
  281.     ;
  282.  
  283. expr    :    '(' expr ')'
  284.             { $$ = $2; }
  285.     |    expr '+' expr
  286.             { if ($1 == 69)
  287.                 {
  288.                   $$ = 2;
  289.                   printf ("$1 became %d\n", $1);
  290.                   $1 = 69;
  291.                 }
  292.               $$ = $1 + $3; }
  293.     |    expr '-' expr
  294.             { $$ = $1 - $3; }
  295.     |    expr '*' expr
  296.             { $$ = $1 * $3; }
  297.     |    expr '/' expr
  298.             { $$ = $1 / $3; }
  299.     |    expr '%' expr
  300.             { $$ = $1 % $3; }
  301.     |    expr '|' expr
  302.             { $$ = $1 | $3; }
  303.     |    expr '&' expr
  304.             { $$ = $1 & $3; }
  305.     |    '-' expr %prec UMINUS
  306.             { $$ = - $2; }
  307.     |    LETTER
  308.             { $$ = regs[$1]; }
  309.     |    number
  310. /*     |    '?'
  311.             { yydebug = !yydebug; }
  312. */    ;
  313.  
  314. number    :    DIGIT
  315.             { $$ = $1;  base = ($1 == 0) ? 8 : 10; }
  316.     |    number DIGIT
  317.             { $$ = base * $1 + $2; }
  318.     ;
  319.  
  320. %%
  321.  
  322. static int eol;
  323.  
  324. int
  325. yylex()
  326. {
  327.   int c;
  328.  
  329.   while ( (c=getchar()) == ' ') {}
  330.   if (c == '\n')
  331.     { eol = 1;
  332.       return 0; }
  333.   if (c == 'Q')
  334.     return(EXIT);
  335.   if (islower(c))
  336.     {
  337.       yylval = c - 'a';
  338.       return (LETTER);
  339.     }
  340.   if (isdigit(c))
  341.     {
  342.       yylval = c - '0';
  343.       return (DIGIT);
  344.     }
  345.   return (c);
  346. }
  347.  
  348. yyerror(s)
  349. char *s;
  350. {
  351.   printf("%s\n", s);
  352. }
  353.  
  354. main()
  355. {
  356.   for (;;)
  357.     {
  358.       eol = 0;
  359.       printflag = 0;
  360.  
  361.       if (yyparse()) printflag = 0;
  362.  
  363.       if (printflag) printf("%d\n", val);
  364.  
  365.       while (!eol) yylex();
  366.     }
  367. }SHAR_EOF
  368. #    End of shell archive
  369. exit 0
  370.  
  371.  
  372.